#ifndef QUSERMESH_H
#define QUSERMESH_H

#include "QMesh_global.h"
#include <QVector>
#include <QMap>
#include <QVector3D>
#include "qmesh.h"

#define S_FLOAT sizeof(float)
typedef QVector<unsigned int> QiboIDs;
typedef QVector<uint> QIndices;
typedef QMap<int,QIndices> QIndicesMap;
typedef unsigned int uint;

class QMESHSHARED_EXPORT QUserMesh
{
public:
    QUserMesh();
protected:
    void Init();

public:
    const int size() const;
    float* GetVertexInfo(int index, int offset);

    const int VertexOff() const{return m_vertexoff;}
    const int NormalOff() const{return m_normaloff;}
    const int ColorOff() const{return m_coloroff;}
    const int UVOff() const{return m_uvoff;}
    const int StructSize() const{return m_structsize;}
    const void* pVertexOff() const{return (void*)(m_vertexoff*S_FLOAT);}
    const void* pNormalOff() const{return (void*)(m_normaloff*S_FLOAT);}
    const void* pColorOff() const{return (void*)(m_coloroff*S_FLOAT);}
    const void* pUVOff() const{return (void*)(m_uvoff*S_FLOAT);}
    const int StructSizef() const{return m_structsize*S_FLOAT;}

    void SetSize(int ssize, int voff, int noff=0, int coff=0, int uvoff=0);

    //Const Get functions
    const QVector<float> Vertices() const{return m_vertices;}
    const uint VBOID() const{return vboID;}
    void VBOID(uint vboid){vboID = vboid;}

    const QVector<uint> Indices() const{return m_indices;}
    const uint IBOID() const{return iboID;}
    void IBOID(uint iboid){iboID = iboid;}

    const QVector<uint> SubIndice(int key) const;
    const QIndicesMap SubIndices() const{return m_subindices;}
    const QiboIDs SubIBOIDs() const {return subiboIDs;}
    void SubIBOIDs(uint* subiboids,int size);

public:
    void GeneratePlane(float x, float y, QVector3D normal, float z, int a=1, int b=1);
    void GenerateSphere(float r, int a, int b);

public:
    void Translate(QVector3D vec3d);
    void Rotate(QMatrix4x4 mat4x4);
    void GaussianNoise(float mean, float std);

protected:
    int m_structsize;

    int m_vertexoff;
    int m_normaloff;
    int m_coloroff;
    int m_uvoff;

    //Vertices Infos
    QVector<float> m_vertices;
    unsigned int vboID;

    QVector<uint> m_indices;
    uint iboID;

    QIndicesMap m_subindices;
    QiboIDs subiboIDs;
};

#endif // QUSERMESH_H
